From 420eae0b60040aa3a4ad50ad2a1202eef316b19b Mon Sep 17 00:00:00 2001 From: robertlipe Date: Fri, 20 Sep 2013 05:21:25 +0000 Subject: [PATCH] Commit the least contestable part of a CL I have in progress. Abandon the idea of a stepping stone "Strings" class. Just go straight to QString, currently behind a #define. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4622 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/defs.h | 50 +++++++--------------------------------------- gpsbabel/gbfile.cc | 23 --------------------- gpsbabel/gbfile.h | 11 ++-------- 3 files changed, 9 insertions(+), 75 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 020ee1678..16390717f 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -437,49 +437,12 @@ const global_trait* get_traits(); * be truncated, edited, or otherwise trimmed should be done on the * way to the target. */ -#if NEW_STRINGS -// Pretty much every occurrence of CSTRc() in the code should be treated -// as a TODO. 90% of them are variadic functions (warning, gbfprint, fatal) -// that should really support stream operators. - -#undef CSTRc -#define CSTRc(s) s.s_ - -class String { - public: - String() : - s_(NULL) {} - - bool isEmpty() const { - return !(s_ && *s_); - } - - // Support things that expect a pointer. Almost all of these will - // ultimately go away, e.g. xfree(shortname); -#if 1 - operator char*() const { - return s_; - } -#endif - // Support shortname = foo; -#if 1 - char* operator=(char* s) { - s_ = s; - return s_; - } -#endif - - // If something is expecting a QString already, just let them have one. - operator QString() const { - return s_; - } - - char* s_; -}; - +#if NEW_STRINGS + typedef QString String; + #define CSTRc(qstr) (qstr.toLatin1().constData()) #else -#define CSTRc(qstr) (qstr) - typedef char* String; + #define CSTRc(qstr) (qstr) + typedef char* String; #endif class waypoint @@ -735,7 +698,7 @@ void waypt_add_url(waypoint* wpt, const QString& link, const QString& url_link_text); void xcsv_setup_internal_style(const char* style_buf); void xcsv_read_internal_style(const char* style_buf); -waypoint* find_waypt_by_name(const char* name); +waypoint* find_waypt_by_name(const QString& name); void waypt_backup(signed int* count, queue** head_bak); void waypt_restore(signed int count, queue* head_bak); @@ -808,6 +771,7 @@ typedef mkshort_handle_imp* short_handle; #ifndef DEBUG_MEM char* mkshort(short_handle, const char*); +char* mkshort(short_handle, const QString&); short_handle mkshort_new_handle(void); #else char* MKSHORT(short_handle, const char*, DEBUG_PARAMS); diff --git a/gpsbabel/gbfile.cc b/gpsbabel/gbfile.cc index 58925f643..e24531e0e 100644 --- a/gpsbabel/gbfile.cc +++ b/gpsbabel/gbfile.cc @@ -794,13 +794,6 @@ gbfputs(const QString& s, gbfile* file) xfree(qs); return rv; } -#if NEW_STRINGS -int -gbfputs(const String& s, gbfile* file) -{ - return gbfwrite(s.s_, 1, strlen(s.s_), file); -} -#endif /* * gbfwrite: (as fwrite) @@ -1247,14 +1240,6 @@ gbfputcstr(const QString& s, gbfile* file) return gbfputcstr(qPrintable(s), file); } -#if NEW_STRINGS -int -gbfputcstr(const String& s, gbfile* file) -{ - return gbfputcstr(s.s_, file); -} -#endif - /* * gbfputcstr: write a pascal string into a stream * return the number of written characters @@ -1285,14 +1270,6 @@ gbfputpstr(const QString& s, gbfile* file) return r; } -#if NEW_STRINGS -int -gbfputpstr(const String& s, gbfile* file) -{ - return gbfputpstr(s.s_, file); -} -#endif - /* Much more higher level functions */ gbsize_t diff --git a/gpsbabel/gbfile.h b/gpsbabel/gbfile.h index 8153021b6..15ff911b4 100644 --- a/gpsbabel/gbfile.h +++ b/gpsbabel/gbfile.h @@ -102,9 +102,8 @@ int gbfprintf(gbfile* file, const char* format, ...); int gbfputc(int c, gbfile* file); int gbfputs(const char* s, gbfile* file); int gbfputs(const QString& s, gbfile* file); -#if NEW_STRINGS -class String; -int gbfputs(const String& s, gbfile* file); +#if NEW_STRINGS +typedef QString String; #endif int gbfwrite(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* file); int gbfflush(gbfile* file); @@ -137,15 +136,9 @@ int gbfputflt(const float f, gbfile* file); // write a float value int gbfputcstr(const char* s, gbfile* file); // write string including '\0' int gbfputcstr(const QString& s, gbfile* file); // write string including '\0' -#if NEW_STRINGS -int gbfputcstr(const String& s, gbfile* file); // write string including '\0' -#endif int gbfputpstr(const char* s, gbfile* file); // write as pascal string int gbfputpstr(const QString& s, gbfile* file); // write as pascal string -#if NEW_STRINGS -int gbfputpstr(const String& s, gbfile* file); // write as pascal string -#endif gbsize_t gbfcopyfrom(gbfile* file, gbfile* src, gbsize_t count); -- 2.30.2